const express = require('express'); 
const pool = require('../pool');
const router = express.Router();

router.get('/list',(req,res,next)=>{
    let obj  = req.obj;
    pool.query('select salary,j_post,j_req,skill,src from join_list',(err,r)=>{
        if(err){
            return next(err)
        }
        
        res.send({code:200,msg:'',data:reArr(r)})
    })
})

router.get('/dail',(req,res,next)=>{
    let obj = req.obj;
    pool.query('select count from job',(err,r)=>{
        if(err){
            return next(err)
        };
        res.send({code:200,msg:'',data:r})
    })
})

function reArr(r){
    let arr=[];
    r.forEach(v => {
        let requirement = v.j_req.split(',')
        let skill = v.skill.split(',')
        let obj = {};
        obj.post = v.j_post;
        obj.salary = v.salary;
        obj.requirement = requirement;
        obj.skill = skill;
        obj.src = v.src,
        arr.push(obj)
    });
    return arr;
}

module.exports = router;